﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions; 

namespace Курс_доллара___погода
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Dollar();
            weather();
        }
        private void Dollar()
        {
            String data = DateTime.Now.Date.ToShortDateString();
            String url = "http://www.cbr.ru/currency_base/D_print.aspx?date_req=";
            url += data;
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            StreamReader myStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream());

            String html = myStreamReader.ReadToEnd();

            String pattern = "Доллар США</td>\r\n<td align=\"right\">(.*)</td>";
            Match match = Regex.Match(html, pattern);
            label1.Text = "Сегодня доллар стоит " + match.Groups[1].ToString() + " рублей"; 
        }
        private void weather()
        {
            String url = "http://msk.nuipogoda.ru";
            
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            StreamReader myStreamReader = new StreamReader(myHttpWebResponse.GetResponseStream());

            String html = myStreamReader.ReadToEnd();

            String pattern = "<div><h2>Температура:</h2>(.*)deg";
            Match match = Regex.Match(html, pattern);
            label2.Text = "В Москве " + match.Groups[1].ToString(); 
        }
    }
}
